package com.songtai.action.front;

import java.util.Date;

import com.songtai.action.SongtaiActionSupport;
import com.songtai.po.Message;
import com.songtai.service.MessageService;
import com.songtai.util.Constants;
import com.songtai.util.Pager;

/**
 * @author zzy
 * @catagory
 */
public class MessageAction extends SongtaiActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8180673794127008680L;
	private String mid;
	private Pager<Message> messages;
	private String name;
	private String sex;
	private String content;
	private int currentPage;
	private MessageService messageService;

	public String execute() throws Exception {
		if (currentPage < 1) {
			currentPage = 1;
		}
		messages = messageService.getAllMessage(currentPage, Constants.DEFAULT_PAGESIEZE);
		return SUCCESS;
	}

	public String writeMsg() throws Exception {
		return SUCCESS;
	}

	public String addMsg() throws Exception {
		if (sex != "1") {
			sex = "0";
		}
		Message msg = new Message();
		msg.setAuther(name);
		msg.setContent(content);
		msg.setIp(request.getRemoteAddr());
		msg.setMsgDate(new Date());
		msg.setSex(sex);
		messageService.addMessage(msg);
		addActionMessage("添加成功!");
		return SUCCESS;
	}

	/**
	 * @return the messageService
	 */
	public MessageService getMessageService() {
		return messageService;
	}

	/**
	 * @param messageService
	 *            the messageService to set
	 */
	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}

	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * @return the mid
	 */
	public String getMid() {
		return mid;
	}

	/**
	 * @param mid
	 *            the mid to set
	 */
	public void setMid(String mid) {
		this.mid = mid;
	}

	/**
	 * @return the messages
	 */
	public Pager<Message> getMessages() {
		return messages;
	}

	/**
	 * @param messages
	 *            the messages to set
	 */
	public void setMessages(Pager<Message> messages) {
		this.messages = messages;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the sex
	 */
	public String getSex() {
		return sex;
	}

	/**
	 * @param sex
	 *            the sex to set
	 */
	public void setSex(String sex) {
		this.sex = sex;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @param content
	 *            the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}

}
